package com.bkgy.modular.tbpaopianpdodata.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.bkgy.controller.stripsteel.mapper.StriSteelMapper;
import com.bkgy.controller.stripsteel.mapper.TPdoDataL3Cal1630Mapper;
import com.bkgy.controller.tpdol3data.entity.TPdoDataL3Cal1630;
import com.bkgy.modular.datacollect_bx.bean.JDataSavemong2280_1;
import com.bkgy.modular.datacollect_bx.bean.JDataSavemong2280_cal1630_norm;
import com.bkgy.modular.qms.entity.QmsCurveDataMongo;
import com.bkgy.modular.tbdsjdatacollect.dao.TbDsjDataCollectDao;
import com.bkgy.modular.tbdsjdatacollect.entity.TbDsjDataCollect;
import com.bkgy.modular.tbpaopianpdodata.dao.TbPaopianPdoDataDao;
import com.bkgy.modular.tbpaopianpdodata.dao.TbTrimWidthDataDao;
import com.bkgy.modular.tbpaopianpdodata.entity.*;
import com.bkgy.modular.tbpaopianpdodata.service.TbPaopianPdoDataService;
import com.bkgy.modular.tpdodata_cal1630.entity.TPdoDataCal1630;
import com.bkgy.modular.tpdodata_cal1630.mapper.TPdoDataCal1630Mapper;
import com.bkgy.modularbx.dataCollection.dao.DataCollectionDao;
import com.bkgy.modularbx.dataCollection.domain.DataCollection;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.util.CodiUtil;
import com.bkgy.util.ExcelUtilsPOI;
import com.bkgy.util.MathUtil;
import com.mongodb.MongoTimeoutException;
import com.mongodb.client.model.BulkWriteOptions;
import com.mongodb.client.model.DeleteOneModel;
import com.mongodb.client.model.WriteModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PipedReader;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * 连退跑偏历史记录接口具体实现类
 *
 * @author 生成器生成
 * @date 2022-08-03 17:10:29
 */
@Service
public class TbPaopianPdoDataServiceImpl implements TbPaopianPdoDataService {

    private static final Logger log = LoggerFactory.getLogger(TbPaopianPdoDataServiceImpl.class);
    @Resource
    private TbPaopianPdoDataDao tbPaopianPdoDataDao;
    @Resource
    private MongoTemplate mongoTemplate;//注入自带的查询工具
    @Resource
    private TPdoDataCal1630Mapper tPdoDataCal1630Mapper;
    @Resource
    private TbTrimWidthDataDao tbTrimWidthDataDao;
    @Resource
    private DataCollectionDao dataCollectionDao;

    /**
     * 添加记录
     *
     * @param data   json字符串
     * @param userId 用户id
     * @param sname  用户姓名
     */
    public ResultData insertDataTbPaopianPdoData(String data, Long userId, String sname) {
        try {
            JTbPaopianPdoData jtbPaopianPdoData = JSON.parseObject(data, JTbPaopianPdoData.class);
            TbPaopianPdoData tbPaopianPdoData = jtbPaopianPdoData.getTbPaopianPdoData();
            CodiUtil.newRecord(userId, sname, tbPaopianPdoData);
            tbPaopianPdoDataDao.insertDataTbPaopianPdoData(tbPaopianPdoData);
            return ResultData.ResultDataSuccessSelf("添加数据成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("添加失败，错误信息为" + e.getMessage(), null);
        }
    }

    /**
     * 根据主键删除对象
     *
     * @param indocno 对象主键
     */
    public ResultData deleteDataTbPaopianPdoDataOne(Long indocno) {
        try {
            tbPaopianPdoDataDao.deleteDataTbPaopianPdoDataOne(indocno);
            return ResultData.ResultDataSuccessSelf("删除数据成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("删除失败,失败信息为" + e.getMessage(), null);
        }
    }

    /**
     * 根据主键字符串删除多个对象
     *
     * @param str_id 对象主键字符串
     */
    public ResultData deleteDataTbPaopianPdoDataMany(String str_id) {
        try {
            String sql = "delete tb_paopian_pdo_data where indocno in(" + str_id + ")";
            tbPaopianPdoDataDao.deleteDataTbPaopianPdoDataMany(sql);
            return ResultData.ResultDataSuccessSelf("删除数据数据成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("删除失败,失败信息为" + e.getMessage(), null);
        }
    }

    /**
     * 修改记录
     *
     * @param userId 用户id
     * @param sname  用户姓名
     * @param data   sysUser 对象实体
     */
    public ResultData updateDataTbPaopianPdoData(String data, Long userId, String sname) {
        try {
            JTbPaopianPdoData jtbPaopianPdoData = JSON.parseObject(data, JTbPaopianPdoData.class);
            TbPaopianPdoData tbPaopianPdoData = jtbPaopianPdoData.getTbPaopianPdoData();
            CodiUtil.editRecord(userId, sname, tbPaopianPdoData);
            tbPaopianPdoDataDao.updateDataTbPaopianPdoData(tbPaopianPdoData);
            return ResultData.ResultDataSuccessSelf("修改成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("修改失败,失败信息为" + e.getMessage(), null);
        }
    }

    /**
     * 分页查看记录
     *
     * @param data 分页参数字符串
     */
    public ResultData findDataTbPaopianPdoDataByPage(String data) {
        try {
            JTbPaopianPdoData jtbPaopianPdoData = JSON.parseObject(data, JTbPaopianPdoData.class);
            JSONObject jsonObject = null;
            Integer pageIndex = jtbPaopianPdoData.getPageIndex();
            Integer pageSize = jtbPaopianPdoData.getPageSize();

            if (null == pageIndex || null == pageSize) {
                return ResultData.ResultDataFaultSelf("分页参数没有传", null);
            }

            if (null != jtbPaopianPdoData.getCondition()) {
                jsonObject = JSON.parseObject(jtbPaopianPdoData.getCondition().toString());
            }

            String dbegin = null;
            if (!StringUtils.isEmpty(jsonObject.get("dbegin"))) {
                dbegin = jsonObject.get("dbegin").toString();
            }
            String dend = null;
            if (!StringUtils.isEmpty(jsonObject.get("dend"))) {
                dend = jsonObject.get("dend").toString();
            }
            String entid = null;  //母卷号
            if (!StringUtils.isEmpty(jsonObject.get("entid"))) {
                entid = jsonObject.get("entid").toString();
            }
            String extid = null;  //母卷号
            if (!StringUtils.isEmpty(jsonObject.get("extid"))) {
                extid = jsonObject.get("extid").toString();
            }
            String steel_grade = null;  //钢种
            if (!StringUtils.isEmpty(jsonObject.get("steel_grade"))) {
                steel_grade = jsonObject.get("steel_grade").toString();
            }

            String grade_code = null;  //钢种分档
            if (!StringUtils.isEmpty(jsonObject.get("grade_code"))) {
                grade_code = jsonObject.get("grade_code").toString();
            }

            String width_code = null;  //宽度分档
            if (!StringUtils.isEmpty(jsonObject.get("width_code"))) {
                width_code = jsonObject.get("width_code").toString();
            }
            String thick_code = null;  //厚度分档
            if (!StringUtils.isEmpty(jsonObject.get("thick_code"))) {
                thick_code = jsonObject.get("thick_code").toString();
            }
            String shift_crew = null;//班组
            if (!StringUtils.isEmpty(jsonObject.get("shift_crew"))) {
                shift_crew = jsonObject.get("shift_crew").toString();
            }
            String shift_no = null;//班次
            if (!StringUtils.isEmpty(jsonObject.get("shift_no"))) {
                shift_no = jsonObject.get("shift_no").toString();
            }


            List<TbPaopianPdoData> list = tbPaopianPdoDataDao.findDataTbPaopianPdoDataByPage((pageIndex - 1) * pageSize, pageIndex * pageSize, dbegin, dend, entid, extid, steel_grade, grade_code, width_code, thick_code, shift_crew, shift_no);
            Integer count = tbPaopianPdoDataDao.findDataTbPaopianPdoDataByPageSize(dbegin, dend, entid, extid, steel_grade, grade_code, width_code, thick_code, shift_crew, shift_no);
            return ResultData.ResultDataSuccess(list, count);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }
    }

    /**
     * 导出功能
     *
     * @param jsonObject
     * @param response
     */
    @Override
    public void export(JSONObject jsonObject, HttpServletResponse response) {
        // 接收传入参数
        Integer pageSize = jsonObject.getInteger("pageSize");
        Integer pageCount = jsonObject.getInteger("pageCount");
        String fileNames = jsonObject.getString("fileName");
        JSONObject condition = jsonObject.getJSONObject("condition");

        String dbegin = null;
        if (!StringUtils.isEmpty(condition.get("dbegin"))) {
            dbegin = condition.get("dbegin").toString();
        }
        String dend = null;
        if (!StringUtils.isEmpty(condition.get("dend"))) {
            dend = condition.get("dend").toString();
        }
        String entid = null;  //母卷号
        if (!StringUtils.isEmpty(condition.get("entid"))) {
            entid = condition.get("entid").toString();
        }
        String extid = null;  //母卷号
        if (!StringUtils.isEmpty(condition.get("extid"))) {
            extid = condition.get("extid").toString();
        }
        String steel_grade = null;  //钢种
        if (!StringUtils.isEmpty(condition.get("steel_grade"))) {
            steel_grade = condition.get("steel_grade").toString();
        }

        String grade_code = null;  //钢种分档
        if (!StringUtils.isEmpty(condition.get("grade_code"))) {
            grade_code = condition.get("grade_code").toString();
        }

        String width_code = null;  //宽度分档
        if (!StringUtils.isEmpty(condition.get("width_code"))) {
            width_code = condition.get("width_code").toString();
        }
        String thick_code = null;  //厚度分档
        if (!StringUtils.isEmpty(condition.get("thick_code"))) {
            thick_code = condition.get("thick_code").toString();
        }


        // 创建表格数据集合
        List<TbPaopianPdoData> listExcel = new ArrayList<>();

        // 调用service查询出数据
        List<TbPaopianPdoData> data = null;
        for (int i = 1; i <= pageCount; i++) {
            // 分页去数据库查询数据 这里可以去数据库查询每一页的数据
            data = tbPaopianPdoDataDao.findDataTbPaopianPdoDataByPage((i - 1) * pageSize, i * pageSize, dbegin, dend, entid, extid, steel_grade, grade_code, width_code, thick_code, null, null);
            for (TbPaopianPdoData item : data) {
                listExcel.add(item);
            }
        }
        // 判断service查询出的数据集合data是否为空
        if (CollectionUtils.isEmpty(data)) {
            return;
        }
//        ExcelUtils.downloadExcel(fileNames,response, TbPaopianPdoData.class,listExcel);
        try {
            ExcelUtilsPOI.exportExcel(listExcel, "连退生产实绩", "连退生产实绩", TbPaopianPdoData.class, "连退生产实绩", response);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 跑偏记录和酸扎曲线的归一化(固定延迟)
     */
    @Override
    public void normWithTcm() {
        log.info("+++++连退跑偏与酸扎曲线归一化(固定延迟)+++++");
        long start = System.currentTimeMillis();
        try {
            // 获取生产结束时间在当前时间前的t_pdo_data_l3_cal1630中完成了的数据
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
            LocalDateTime now = LocalDateTime.now();
            String nowFormat = now.format(formatter);
            List<TPdoDataCal1630> tpdoDataCal1630List = tPdoDataCal1630Mapper.selectWithSubQuery(nowFormat);
            if (CollectionUtils.isEmpty(tpdoDataCal1630List)) {
                log.warn("未查询到符合条件的t_pdo_data_l3_cal1630数据,无法进行连退1630-酸扎曲线归一化");
                return;
            }
            // 使用entid分组
            Map<String, List<TPdoDataCal1630>> entidCollect = tpdoDataCal1630List.stream()
                    .filter(Objects::nonNull)
                    .filter(obj -> obj.getEntid() != null)
                    .collect(Collectors.groupingBy(
                            TPdoDataCal1630::getEntid,
                            Collectors.collectingAndThen(
                                    Collectors.toList(),
                                    Collections::unmodifiableList
                            )
                    ));
            // 获取TCM2280对应的l1_variable_name
            QueryWrapper<DataCollection> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("variable_property", 2);
            queryWrapper.eq("enable", 1);
            queryWrapper.eq("production_line", "TCM2280");
            List<DataCollection> alias = dataCollectionDao.selectList(queryWrapper);
            List<String> l1_variable_nameList = alias.stream().map(DataCollection::getL1VariableAlias).collect(Collectors.toList());
            // okEntid:完成归一化的entid
            List<String> okEntid = new ArrayList<>();
            // emptyEntid:curve曲线为空的entid
            List<String> emptyEntid = new ArrayList<>();

            entidCollect.forEach((key, value) -> {
                // 入口id就是当前的key后三位+000

                value.forEach(item -> {
                    log.info("当前入口id:{}-当前出口id:{}", key, item.getExtid());
                });
                // 获得切头尾长度
                TbTrimWidthData tbTrimWidthData = tbTrimWidthDataDao.selectOne(new QueryWrapper<TbTrimWidthData>().eq("entid", key).eq("LINE", "CAL1630"));
                if (tbTrimWidthData == null) {
                    log.error("未查询到{}的切头切尾长度数据,无法进行连退1630-酸扎曲线归一化", key);
                    return;
                }
                Query query = new Query();
                query.addCriteria(Criteria.where("extid").is(key))
                        .addCriteria(Criteria.where("var_name").in(l1_variable_nameList));

                List<JDataSavemong2280_1> listdatas = mongoTemplate.find(query, JDataSavemong2280_1.class);
                if (listdatas.size() > 0) {
                    // 连退出口总长度
                    int exAllLen = value.stream().map(TPdoDataCal1630::getOutMatActLen).reduce(0, Integer::sum);
                    if (exAllLen == 0) {
                        log.error("出口总长度为0,无法进行连退1630-酸扎曲线归一化");
                        return;
                    }
                    log.info("listdatas总长度:{}", listdatas.size());
                    List<JDataSavemong2280_cal1630_norm> jDataSavemong2280Cal1630Norms = new ArrayList<>();
                    List<String> collect = listdatas.stream().map(JDataSavemong2280_1::getVar_name).collect(Collectors.toList());
                    query = new Query();
                    query.addCriteria(Criteria.where("extid").is(key))
                            .addCriteria(Criteria.where("var_name").in(collect));
                    query.maxTime(30, TimeUnit.SECONDS); // 设置超时
                    long exnum = mongoTemplate.count(query, JDataSavemong2280_cal1630_norm.class);
                    if (exnum > 0) {
                        int batchSize = 100;
                        List<String> varNames = collect;
                        for (int i = 0; i < varNames.size(); i += batchSize) {
                            List<String> batchVars = varNames.subList(i, Math.min(i + batchSize, varNames.size()));

                            Query batchQuery = new Query();
                            batchQuery.addCriteria(Criteria.where("extid").is(key))
                                    .addCriteria(Criteria.where("var_name").in(batchVars));
                            batchQuery.maxTime(10, TimeUnit.SECONDS);
                            mongoTemplate.remove(batchQuery, JDataSavemong2280_cal1630_norm.class);
                            // 小延迟，避免对数据库造成过大压力
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException ie) {
                                Thread.currentThread().interrupt();
                            }
                        }
                    }
                    for (JDataSavemong2280_1 listdata : listdatas) {
                        // 获取曲线
                        List<Double> curve = listdata.getCurve();
                        if (curve.isEmpty()) {
                            log.error("{}的{}曲线为空,无法进行连退1630-酸扎曲线归一化", key, listdata.getVar_name());
                            continue;
                        }
                        // 反转逆序
                        Collections.reverse(curve);

                        int cut_head_len = tbTrimWidthData.getTrCutHeadLen().intValue(); // 去头长度
                        int cut_tail_len = tbTrimWidthData.getTrCutTailLen().intValue(); // 去尾长度
                        //去头、去尾
                        List<Double> cutCurve = curve.subList(cut_head_len, curve.size() - cut_tail_len);
                        //去头尾后的curve曲线长度
                        double cutCurveLength = cutCurve.size();
                        // 获取比例系数
                        double bs = exAllLen / cutCurveLength;
                        List<Double> speedslength = new ArrayList<>();
                        for (int i = 1; i <= cutCurveLength; i++) {
                            speedslength.add(i * bs);
                        }
                        JSONObject jsongetLength = new JSONObject();
                        jsongetLength.put("speedslength", speedslength);
                        jsongetLength.put("datas", cutCurve);
                        jsongetLength.put("MULTIPLIER", 1);
                        String jsonStringL = JSON.toJSONString(jsongetLength, SerializerFeature.DisableCircularReferenceDetect);
                        List<Double> listdatas_L = timetolengenddata(jsonStringL);
                        Collections.reverse(listdatas_L);
                        JDataSavemong2280_cal1630_norm jDataSavemong2280Cal1630Norm = new JDataSavemong2280_cal1630_norm();
                        jDataSavemong2280Cal1630Norm.setExtid(key);
                        jDataSavemong2280Cal1630Norm.setEntid(listdata.getEntid());
                        jDataSavemong2280Cal1630Norm.setStart("0");
                        jDataSavemong2280Cal1630Norm.setEnd(String.valueOf(listdatas_L.size() - 1));
                        jDataSavemong2280Cal1630Norm.setVar_name(listdata.getVar_name());
                        jDataSavemong2280Cal1630Norm.setCurve(listdatas_L);
                        jDataSavemong2280Cal1630Norm.setFlag(listdata.getFlag());
                        jDataSavemong2280Cal1630Norm.setTrailValues(listdata.getTrailValues());
                        jDataSavemong2280Cal1630Norm.setCreatetime(new Date());
                        jDataSavemong2280Cal1630Norms.add(jDataSavemong2280Cal1630Norm);
                    }
                    mongoTemplate.insertAll(jDataSavemong2280Cal1630Norms);
                    okEntid.add(key);
                } else {
                    log.error("未查询到{}的曲线数据，无法进行连退1630-酸扎曲线归一化", key);
                    emptyEntid.add(key);
                }
            });
            if (!okEntid.isEmpty()) {
                UpdateWrapper<TPdoDataCal1630> tPdoDataCal1630UpdateWrapper = new UpdateWrapper<>();
                tPdoDataCal1630UpdateWrapper.set("norm", 1)
                        .in("entid", okEntid);
                int i = tPdoDataCal1630Mapper.update(null, tPdoDataCal1630UpdateWrapper);
                if (i > 0) {
                    log.info("连退1630-酸扎曲线归一化数据成功,更新{}条数据", i);
                } else {
                    log.error("连退1630-酸扎曲线归一化数据失败,更新0条数据");
                }
            } else {
                log.error("连退1630-酸扎曲线归一化数据失败,okEntid为空");
            }
            if (!emptyEntid.isEmpty()) {
                UpdateWrapper<TPdoDataCal1630> updateWrapper = new UpdateWrapper<>();
                updateWrapper.set("curve_flag", 0);
                updateWrapper.in("entid", emptyEntid);
                int i = tPdoDataCal1630Mapper.update(null, updateWrapper);
                if (i > 0) {
                    log.info("连退1630-无酸扎曲线标志更新成功,更新{}条数据", i);
                } else {
                    log.error("连退1630-无酸扎曲线标志更新失败,更新0条数据");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("连退1630-酸扎曲线归一化数据失败,异常信息:{}", e.getMessage());
        }
        long end = System.currentTimeMillis();
        log.info("连退1630-酸扎曲线归一化开始时间: " + start + ";结束时间: " + end + ";耗时ms: " + (end - start));
    }

    private List<Double> timetolengenddata(String jsonStringL) {
        JSONObject jsonresLength = JSONObject.parseObject(jsonStringL);
        JSONArray speeds = jsonresLength.getJSONArray("speedslength");
        JSONArray datas = jsonresLength.getJSONArray("datas");
        double MULTIPLIER = jsonresLength.getDouble("MULTIPLIER");
        List<Double> listspeeds = speeds.toJavaList(Double.class);
        List<Double> listdatas = datas.toJavaList(Double.class);
        List<Integer> listindex = new ArrayList<>();
        for (int i = 0; i < listspeeds.size(); i++) {
            double floorValue = Math.floor(listspeeds.get(i)); // 向下取整 Math.ceil(listspeeds.get(i));
            int intFloorValue = (int) floorValue; // 转换为int类型
            if (intFloorValue >= 0) {
                listindex.add(intFloorValue);
            }
        }
        List<Double> listdatasL = new ArrayList<>();
        for (int i = 0; i < listindex.size() - 1; i++) {
            if (i == 0) {
                int cha = listindex.get(i) - 0;
                if (cha == 1) {
                    listdatasL.add(listdatas.get(i));
                } else {
                    if (cha > 0) {
                        double chazhi = (listdatas.get(i + 1) - listdatas.get(i)) / cha;
                        for (int k = 1; k < cha; k++) {
                            listdatasL.add(listdatas.get(i) + k * chazhi);
                        }
                        listdatasL.add(listdatas.get(i + 1));
                    }
                }
            }
            int cha = listindex.get(i + 1) - listindex.get(i);
            if (cha == 1) {
                listdatasL.add(listdatas.get(i + 1));
            } else {
                if (cha > 0) {
                    double chazhi = (listdatas.get(i + 1) - listdatas.get(i)) / cha;
                    for (int k = 1; k < cha; k++) {
                        listdatasL.add(listdatas.get(i) + k * chazhi);
                    }
                    listdatasL.add(listdatas.get(i + 1));
                }
            }
        }
        return listdatasL.stream()
                .map(d -> d * MULTIPLIER)
                .collect(Collectors.toList());
    }

    private String getExtidPrefix(String extid) {
        if (extid == null || extid.length() <= 3) {
            return extid; // 如果长度不足3位，返回原值
        }
        return extid.substring(0, extid.length() - 3);
    }

    /**
     * 不分页查看记录
     *
     * @param data 分页参数字符串
     */
    public ResultData findDataTbPaopianPdoDataByPage3(String data) {
        try {
            JTbPaopianPdoData jtbPaopianPdoData = JSON.parseObject(data, JTbPaopianPdoData.class);
            JSONObject jsonObject = null;

            if (null != jtbPaopianPdoData.getCondition()) {
                jsonObject = JSON.parseObject(jtbPaopianPdoData.getCondition().toString());
            }

            String dbegin = null;
            if (!StringUtils.isEmpty(jsonObject.get("dbegin"))) {
                dbegin = jsonObject.get("dbegin").toString();
            }
            String dend = null;
            if (!StringUtils.isEmpty(jsonObject.get("dend"))) {
                dend = jsonObject.get("dend").toString();
            }
            String entid = null;  //母卷号
            if (!StringUtils.isEmpty(jsonObject.get("entid"))) {
                entid = jsonObject.get("entid").toString();
            }
            String extid = null;  //母卷号
            if (!StringUtils.isEmpty(jsonObject.get("extid"))) {
                extid = jsonObject.get("extid").toString();
            }
            String steel_grade = null;  //钢种
            if (!StringUtils.isEmpty(jsonObject.get("steel_grade"))) {
                steel_grade = jsonObject.get("steel_grade").toString();
            }

            String grade_code = null;  //钢种分档
            if (!StringUtils.isEmpty(jsonObject.get("grade_code"))) {
                grade_code = jsonObject.get("grade_code").toString();
            }

            String width_code = null;  //宽度分档
            if (!StringUtils.isEmpty(jsonObject.get("width_code"))) {
                width_code = jsonObject.get("width_code").toString();
            }
            String thick_code = null;  //厚度分档
            if (!StringUtils.isEmpty(jsonObject.get("thick_code"))) {
                thick_code = jsonObject.get("thick_code").toString();
            }

            List<TbPaopianPdoData> list = tbPaopianPdoDataDao.findDataTbPaopianPdoDataNoPage(dbegin, dend, entid, extid, steel_grade, grade_code, width_code, thick_code);
            Integer count = tbPaopianPdoDataDao.findDataTbPaopianPdoDataByPageSize(dbegin, dend, entid, extid, steel_grade, grade_code, width_code, thick_code, null, null);
            return ResultData.ResultDataSuccess(list, count);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }
    }

    /**
     * 分页查看记录
     *
     * @param data 分页参数字符串
     */
    public ResultData findDataTbPaopianPdoDataByPage2(String data) {
        try {
            JTbPaopianPdoData jtbPaopianPdoData = JSON.parseObject(data, JTbPaopianPdoData.class);
            JSONObject jsonObject = null;

            if (null != jtbPaopianPdoData.getCondition()) {
                jsonObject = JSON.parseObject(jtbPaopianPdoData.getCondition().toString());
            }

            String dbegin = null;
            if (!StringUtils.isEmpty(jsonObject.get("dbegin"))) {
                dbegin = jsonObject.get("dbegin").toString();
            }
            String dend = null;
            if (!StringUtils.isEmpty(jsonObject.get("dend"))) {
                dend = jsonObject.get("dend").toString();
            }
            TbPaopianPdoAvgStd avgStd = tbPaopianPdoDataDao.findAvgStd(dbegin, dend);
            List<TbPaopianPdoAllData> allData = tbPaopianPdoDataDao.findAllData(dbegin, dend);
            List<TbPaopianPdoAllData> tbPaopianPdoAllData = cal2Num(allData);
            return ResultData.ResultDataSuccess(avgStd, 0, tbPaopianPdoAllData);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }
    }

    /**
     * 根据主键查询单条记录
     *
     * @param data 分页参数字符串
     */
    public ResultData findDataTbPaopianPdoDataByIndocno(String data) {
        try {
            JTbPaopianPdoData jtbPaopianPdoData = JSON.parseObject(data, JTbPaopianPdoData.class);
            Long indocno = jtbPaopianPdoData.getIndocno();

            TbPaopianPdoData tbPaopianPdoData = tbPaopianPdoDataDao.findDataTbPaopianPdoDataByIndocno(indocno);
            return ResultData.ResultDataSuccess(tbPaopianPdoData);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }
    }

    /**
     * 查看记录
     *
     * @return list 对象集合返回
     */
    public List<TbPaopianPdoData> findDataTbPaopianPdoData() {
        List<TbPaopianPdoData> list = tbPaopianPdoDataDao.findDataTbPaopianPdoData();
        return list;
    }

    @Override
    public ResultData findDataTbPaopianPdoDatatuxie(String data) {
        try {
            JTbPaopianPdoData jtbPaopianPdoData = JSON.parseObject(data, JTbPaopianPdoData.class);
            JSONObject jsonObject = null;
            Integer pageIndex = jtbPaopianPdoData.getPageIndex();
            Integer pageSize = jtbPaopianPdoData.getPageSize();

            if (null == pageIndex || null == pageSize) {
                return ResultData.ResultDataFaultSelf("分页参数没有传", null);
            }

            if (null != jtbPaopianPdoData.getCondition()) {
                jsonObject = JSON.parseObject(jtbPaopianPdoData.getCondition().toString());
            }

            String volumeNo = null;  //母卷号
            if (!StringUtils.isEmpty(jsonObject.get("volumeNo"))) {
                volumeNo = jsonObject.get("volumeNo").toString();
            }
            Map<String, Object> mapa_1 = new HashMap<>();//mongdb   点
            String mat_no1 = volumeNo.substring(volumeNo.length() - 1);//截取的字段
            System.out.print(mat_no1.charAt(0) - 0);
            if ((mat_no1.charAt(0) - 0) <= 57 && (mat_no1.charAt(0) - 0) >= 48) {
                //末尾为数字的
                String mat_nozong = volumeNo.substring(0, volumeNo.length() - 1);//截取剩余字段
                //模糊查询
                Query query = new Query(Criteria.where("volumeNo").regex(mat_nozong));
                List<QmsCurveDataMongo> list_mongdb = mongoTemplate.find(query, QmsCurveDataMongo.class);
                System.out.print("1");
                for (QmsCurveDataMongo entity : list_mongdb) {
                    Map<String, List<Double>> originBolg = entity.getOriginBolg();
                    originBolg.forEach((key, value) -> {
                        if (key.equals("hsm_crown_c40") || key.equals("hsm_flatness_wedge40")) {
                            mapa_1.put(key, value);
                        }
                    });
                }
            } else {
                //查询
                Query query = new Query(Criteria.where("volumeNo").is(volumeNo));
                List<QmsCurveDataMongo> list_mongdb = mongoTemplate.find(query, QmsCurveDataMongo.class);
                for (QmsCurveDataMongo entity : list_mongdb) {
                    Map<String, List<Double>> originBolg = entity.getOriginBolg();
                    originBolg.forEach((key, value) -> {
                        if (key.equals("hsm_crown_c40") || key.equals("hsm_flatness_wedge40")) {
                            mapa_1.put(key, value);
                        }
                    });
                }
                System.out.print("2");
            }
            return ResultData.ResultDataSuccess(mapa_1, 0);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }
    }

    /**
     * 分页查看记录
     *
     * @param data 分页参数字符串
     */
    public ResultData findDataTbPaopianPdoonetwo(String data) {
        try {
            JTbPaopianPdoData jtbPaopianPdoData = JSON.parseObject(data, JTbPaopianPdoData.class);
            JSONObject jsonObject = null;

            if (null != jtbPaopianPdoData.getCondition()) {
                jsonObject = JSON.parseObject(jtbPaopianPdoData.getCondition().toString());
            }
            String extid = null;  //母卷号
            if (!StringUtils.isEmpty(jsonObject.get("extid"))) {
                extid = jsonObject.get("extid").toString();
            }

            Query query = new Query(Criteria.where("EXTID").is(extid));
            List<paopian_asc> list_paopian_asc = mongoTemplate.find(query, paopian_asc.class);

            return ResultData.ResultDataSuccess(list_paopian_asc, 0);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }
    }

    public ResultData findHighestSteelGradeByDate(String data) {
        try {
            TbPaopianPdoDataByDate jtbPaopianPdoData = JSON.parseObject(data, TbPaopianPdoDataByDate.class);
            List<paopian_higheststeelgrade> list = tbPaopianPdoDataDao.findHighestSteelGradeByDate(jtbPaopianPdoData);

            return ResultData.ResultDataSuccess(list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }


    }

    public ResultData findHighestSpecificationsByDate(String data) {
        try {
            TbPaopianPdoDataByDate jtbPaopianPdoData = JSON.parseObject(data, TbPaopianPdoDataByDate.class);
            List<paopian_higheststeelgrade> list = tbPaopianPdoDataDao.findHighestSpecificationsByDate(jtbPaopianPdoData);

            return ResultData.ResultDataSuccess(list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }


    }


    /**
     * 宽度\厚度\钢种分档框
     *
     * @return list 对象集合返回
     */
    public List<select_value> findDataTbPaopianPdoDataselect(String data) {
        //1为宽度，2为厚度，3为钢种
        select_value select_value1 = JSON.parseObject(data, select_value.class);
        JSONObject jsonObject = null;
        String keys = select_value1.getKey();
        List<select_value> list = new ArrayList<>();
        List<cal_thk_wid_2130> listm = new ArrayList<>();
        if (keys.equals("1")) {
            //"1"为宽度
            listm = tbPaopianPdoDataDao.findDataTbPaopianPdoData_wid();

            for (int i = 0; listm.size() > i; i++) {
                if (i == 0) {
                    select_value entity = new select_value();
                    entity.setKey(listm.get(i).getClassid());
                    entity.setValue("0-" + listm.get(i).getWid_class());
                    list.add(entity);
                } else {
                    select_value entity = new select_value();
                    entity.setKey(listm.get(i).getClassid());
                    entity.setValue(listm.get(i - 1).getWid_class() + "-" + listm.get(i).getWid_class());
                    list.add(entity);
                }
            }
        } else if (keys.equals("2")) {
            //"2"为厚度
            listm = tbPaopianPdoDataDao.findDataTbPaopianPdoData_thk();
            for (int i = 0; listm.size() > i; i++) {
                if (i == 0) {
                    select_value entity = new select_value();
                    entity.setKey(listm.get(i).getClassid());
                    entity.setValue("0-" + listm.get(i).getThk_class());
                    list.add(entity);
                } else {
                    select_value entity = new select_value();
                    entity.setKey(listm.get(i).getClassid());
                    entity.setValue(listm.get(i - 1).getThk_class() + "-" + listm.get(i).getThk_class());
                    list.add(entity);
                }
            }
        } else if (keys.equals("3")) {
            //"3"为刚度
            listm = tbPaopianPdoDataDao.findDataTbPaopianPdoData_yp();
            for (int i = 0; listm.size() > i; i++) {
                select_value entity = new select_value();
                entity.setKey(listm.get(i).getClassid());
                entity.setValue(listm.get(i).getYp_class());
                list.add(entity);
            }
        }
        return list;
    }

    /**
     * 连退跑偏归档统计分析查询
     */
    @Override
    public ResultData findlx(JSONObject jsonObject) {
        try {
            JSONObject condition = jsonObject.getJSONObject("condition");
            List<Jpaopian_lx> jlxList = new ArrayList<>();
            List<paopian_lx> plxList = tbPaopianPdoDataDao.findlx(condition);
            List<cal_thk_wid_2130> calList = tbPaopianPdoDataDao.findDatacal();
            if (!StringUtils.isEmpty(plxList)) {
                plxList = plxList.stream().filter(x -> x.getGrade_code() != 0).collect(Collectors.toList());
                if (!StringUtils.isEmpty(calList)) {
                    for (paopian_lx entity : plxList) {
                        if (entity.getGrade_code() != null) {
                            Jpaopian_lx jpaopian_lx = new Jpaopian_lx();

                            BeanUtils.copyProperties(entity, jpaopian_lx);
                            //规则号：钢种+宽度+厚度
                            String str_No = String.valueOf(entity.getGrade_code().intValue()) + entity.getWidth_code().intValue() + entity.getThick_code().intValue();
                            jpaopian_lx.setStr_No(str_No);

                            //钢种：id+name
                            //用钢种id查找钢种名称
                            cal_thk_wid_2130 cal1 = findstands(calList, String.valueOf(entity.getGrade_code().intValue()));
                            String str_grade_code = entity.getGrade_code().intValue() + ":" + cal1.getYp_class();
                            jpaopian_lx.setStr_grade_code(str_grade_code);

                            //宽度：最小值（前一条）+“-”+最大值（当前）
                            String str_width;
                            //获取宽度标准最大值（即当前宽度标准）
                            cal_thk_wid_2130 calwidth = findstands(calList, String.valueOf(entity.getWidth_code().intValue()));
                            //获取宽度标准最小值（即前一等级的宽度标准）
                            cal_thk_wid_2130 calwidth_up = findstands(calList, String.valueOf(entity.getWidth_code().intValue() - 1));
                            if (entity.getWidth_code().intValue() != 1) {
                                str_width = entity.getWidth_code().intValue() + ":" + calwidth_up.getWid_class() + "-" + calwidth.getWid_class();
                            } else {
                                str_width = entity.getWidth_code().intValue() + ":" + "0-" + calwidth.getWid_class();
                            }

                            jpaopian_lx.setStr_width(str_width);

                            //厚度：最小值（前一条）+“-”+最大值（当前）
                            String str_thick;
                            //获取厚度标准最大值（即当前厚度标准）
                            cal_thk_wid_2130 calthk = findstands(calList, String.valueOf(entity.getThick_code().intValue()));
                            //获取宽度标准最小值（即前一等级的宽度标准）
                            cal_thk_wid_2130 calthk_up = findstands(calList, String.valueOf(entity.getThick_code().intValue() - 1));
                            if (entity.getThick_code().intValue() != 1) {
                                str_thick = entity.getThick_code().intValue() + ":" + calthk_up.getThk_class() + "-" + calthk.getThk_class();
                            } else {
                                str_thick = entity.getThick_code().intValue() + ":" + "0-" + calthk.getThk_class();
                            }
                            jpaopian_lx.setStr_thick(str_thick);

                            //跑偏概率
                            jpaopian_lx.setStr_rate(String.valueOf(entity.getGrade_paopian_rate()));

                            //跑偏卷数
                            jpaopian_lx.setStr_num(String.valueOf(entity.getPaopian_num().intValue()));

                            //总卷数
                            jpaopian_lx.setStr_sum(String.valueOf(entity.getSum_num().intValue()));
                            jlxList.add(jpaopian_lx);
                        }
                    }
                }
            }
            return ResultData.ResultDataSuccess(jlxList, jlxList.size());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }
    }

    /**
     * 时间区域分析
     *
     * @param data
     */
    @Override
    public ResultData findTime(String data) {
        try {

            JTbPaopianPdoData jtbPaopianPdoData = JSON.parseObject(data, JTbPaopianPdoData.class);
            JSONObject jsonObject = null;

            if (null != jtbPaopianPdoData.getCondition()) {
                jsonObject = JSON.parseObject(jtbPaopianPdoData.getCondition().toString());
            }

            String dbegin = null;
            if (!StringUtils.isEmpty(jsonObject.get("dbegin"))) {
                dbegin = jsonObject.get("dbegin").toString();
            }
            String dend = null;
            if (!StringUtils.isEmpty(jsonObject.get("dend"))) {
                dend = jsonObject.get("dend").toString();
            }

            List<TbPaopianPdoData> listx = tbPaopianPdoDataDao.findDataTbPaopianPdoDataNoPage(dbegin, dend, null, null, null, null, null, null);
            TbPaopianPdoData_stddev liststddev = tbPaopianPdoDataDao.findDataStddevNoPage(dbegin, dend, null, null, null, null, null);
            List<paopian_time_area> list = new ArrayList<>();
            if (!StringUtils.isEmpty(listx) && listx.size() != 0) {
                list.add(pchange("清洗段", 1L, listx, liststddev));
                list.add(pchange("活套段", 2L, listx, liststddev));
                list.add(pchange("加热段", 3L, listx, liststddev));
                list.add(pchange("均热段", 4L, listx, liststddev));
                list.add(pchange("时效段", 5L, listx, liststddev));
                list.add(pchange("终冷段", 6L, listx, liststddev));
            }
            return ResultData.ResultDataSuccess(list, list.size());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }
    }

    /**
     * 分区域计算
     *
     * @param name       区域名称
     * @param l          标志
     * @param listx      数据集合
     * @param liststddev
     * @return 计算结果
     */
    private paopian_time_area pchange(String name, long l, List<TbPaopianPdoData> listx, TbPaopianPdoData_stddev liststddev) {
        paopian_time_area p = new paopian_time_area();
        p.setSarea(name);
        p.setCpc_total_avg(cpc_avg(l, listx));
        p.setCpc_st(cpc_ct(l, liststddev));
        p.setCpc_strip(cpc_strip(l, listx));
        p.setCpc_strip_cpc_st(cpc_strip_cpc_st(l, liststddev));
        return p;
    }

    /**
     * 带钢标准差
     *
     * @param l          标志
     * @param liststddev 标准差数据
     * @return 集合
     */
    private Double cpc_strip_cpc_st(long l, TbPaopianPdoData_stddev liststddev) {
        double result;
        List<Double> y = new ArrayList<>();
        if (l == 1L) {
            y.add(liststddev.getCpc1_strip_pos_stddev());
            y.add(liststddev.getCpc2_strip_pos_stddev());
            y.add(liststddev.getCpc3_strip_pos_stddev());
        } else if (l == 2L) {

        } else if (l == 3L) {
            y.add(liststddev.getCpc4a_strip_pos_stddev());
            y.add(liststddev.getCpc4_strip_pos_stddev());
            y.add(liststddev.getCpc5a_strip_pos_stddev());
            y.add(liststddev.getCpc5_strip_pos_stddev());
        } else if (l == 4L) {
            y.add(liststddev.getCpc6_strip_pos_stddev());
        } else if (l == 5L) {
            y.add(liststddev.getCpc7_strip_pos_stddev());
            y.add(liststddev.getCpc8_strip_pos_stddev());
            y.add(liststddev.getCpc9_strip_pos_stddev());
        } else {
            y.add(liststddev.getCpc10_strip_pos_stddev());
        }
        y.removeIf(Objects::isNull);
        result = y.stream().mapToDouble(Double::doubleValue).average().orElse(0D);
        return result;
    }

    /**
     * 带钢均值
     *
     * @param l     标志
     * @param listx 数据集合
     * @return 集合
     */
    private Double cpc_strip(long l, List<TbPaopianPdoData> listx) {
        double result;
        List<Double> y = new ArrayList<>();
        for (TbPaopianPdoData entity : listx) {
            List<Double> x1 = new ArrayList<>();
            if (l == 1L) {
                x1.add(entity.getCpc1_strip_pos_avg());
                x1.add(entity.getCpc2_strip_pos_avg());
                x1.add(entity.getCpc3_strip_pos_avg());
            } else if (l == 2L) {

            } else if (l == 3L) {
                x1.add(entity.getCpc4a_strip_pos_avg());
                x1.add(entity.getCpc4_strip_pos_avg());
                x1.add(entity.getCpc5a_strip_pos_avg());
                x1.add(entity.getCpc5_strip_pos_avg());
            } else if (l == 4L) {
                x1.add(entity.getCpc6_strip_pos_avg());
            } else if (l == 5L) {
                x1.add(entity.getCpc7_strip_pos_avg());
                x1.add(entity.getCpc8_strip_pos_avg());
                x1.add(entity.getCpc9_strip_pos_avg());
            } else {
                x1.add(entity.getCpc10_strip_pos_avg());
            }
            x1.removeIf(Objects::isNull);
            double x = x1.stream().mapToDouble(Double::doubleValue).average().orElse(0D);
            y.add(x);
        }
        result = y.stream().mapToDouble(Double::doubleValue).average().orElse(0D);
        return result;
    }

    /**
     * 纠偏标准差
     *
     * @param l          标志
     * @param liststddev 标准差数据
     * @return 集合
     */
    private Double cpc_ct(long l, TbPaopianPdoData_stddev liststddev) {
        double result;
        List<Double> y = new ArrayList<>();
        if (l == 1L) {
            y.add(liststddev.getCpc1_stddev());
            y.add(liststddev.getCpc2_stddev());
            y.add(liststddev.getCpc3_stddev());
        } else if (l == 2L) {

        } else if (l == 3L) {
            y.add(liststddev.getCpc4a_stddev());
            y.add(liststddev.getCpc4_stddev());
            y.add(liststddev.getCpc5a_stddev());
            y.add(liststddev.getCpc5_stddev());
        } else if (l == 4L) {
            y.add(liststddev.getCpc6_stddev());
        } else if (l == 5L) {
            y.add(liststddev.getCpc7_stddev());
            y.add(liststddev.getCpc8_stddev());
            y.add(liststddev.getCpc9_stddev());
        } else {
            y.add(liststddev.getCpc10_stddev());
        }
        y.removeIf(Objects::isNull);
        result = y.stream().mapToDouble(Double::doubleValue).average().orElse(0D);
        return result;
    }

    /**
     * 纠偏平均值
     *
     * @param l     标志
     * @param listx 数据集合
     * @return 集合
     */
    private Double cpc_avg(long l, List<TbPaopianPdoData> listx) {
        double result;
        List<Double> y = new ArrayList<>();
        for (TbPaopianPdoData entity : listx) {
            List<Double> x1 = new ArrayList<>();
            if (l == 1L) {
                x1.add(entity.getCpc1_avg());
                x1.add(entity.getCpc2_avg());
                x1.add(entity.getCpc3_avg());
            } else if (l == 2L) {

            } else if (l == 3L) {
                x1.add(entity.getCpc4a_avg());
                x1.add(entity.getCpc4_avg());
                x1.add(entity.getCpc5a_avg());
                x1.add(entity.getCpc5_avg());
            } else if (l == 4L) {
                x1.add(entity.getCpc6_avg());
            } else if (l == 5L) {
                x1.add(entity.getCpc7_avg());
                x1.add(entity.getCpc8_avg());
                x1.add(entity.getCpc9_avg());
            } else {
                x1.add(entity.getCpc10_avg());
            }
            x1.removeIf(Objects::isNull);
            double x = x1.stream().mapToDouble(Double::doubleValue).average().orElse(0D);
            y.add(x);
        }
        result = y.stream().mapToDouble(Double::doubleValue).average().orElse(0D);
        return result;
    }

    //根据id查找指定标准
    public cal_thk_wid_2130 findstands(List<cal_thk_wid_2130> list, String id) {
        List<cal_thk_wid_2130> calList = list.stream().filter(x -> id.equals(x.getClassid())).collect(Collectors.toList());
        cal_thk_wid_2130 cal = new cal_thk_wid_2130();
        if (calList.size() != 0) {
            cal = calList.get(0);
        }
        return cal;
    }

    private List<TbPaopianPdoAllData> cal2Num(List<TbPaopianPdoAllData> list) {
        list.forEach(x -> {
            x.setCpc1_avg(MathUtil.tofixed(x.getCpc1_avg(), 2));
            x.setCpcpor1_avg(MathUtil.tofixed(x.getCpcpor1_avg(), 2));
            x.setCpcpor2_avg(MathUtil.tofixed(x.getCpcpor2_avg(), 2));
            x.setCpc1_avg(MathUtil.tofixed(x.getCpc1_avg(), 2));
            x.setCpc2_avg(MathUtil.tofixed(x.getCpc2_avg(), 2));
            x.setCpc3_avg(MathUtil.tofixed(x.getCpc3_avg(), 2));
            x.setCpc4a_avg(MathUtil.tofixed(x.getCpc4a_avg(), 2));
            x.setCpc4_avg(MathUtil.tofixed(x.getCpc4_avg(), 2));
            x.setCpc5a_avg(MathUtil.tofixed(x.getCpc5a_avg(), 2));
            x.setCpc5_avg(MathUtil.tofixed(x.getCpc5_avg(), 2));
            x.setCpc6_avg(MathUtil.tofixed(x.getCpc6_avg(), 2));
            x.setCpc7_avg(MathUtil.tofixed(x.getCpc7_avg(), 2));
            x.setCpc8_avg(MathUtil.tofixed(x.getCpc8_avg(), 2));
            x.setCpc9_avg(MathUtil.tofixed(x.getCpc9_avg(), 2));
            x.setCpc10_avg(MathUtil.tofixed(x.getCpc10_avg(), 2));
            x.setCpc11_avg(MathUtil.tofixed(x.getCpc11_avg(), 2));
            x.setCpc12_avg(MathUtil.tofixed(x.getCpc12_avg(), 2));
            x.setCpc13_avg(MathUtil.tofixed(x.getCpc13_avg(), 2));
            x.setCpc14_avg(MathUtil.tofixed(x.getCpc14_avg(), 2));
            x.setCpc15_avg(MathUtil.tofixed(x.getCpc15_avg(), 2));
            x.setCpc16a_avg(MathUtil.tofixed(x.getCpc16a_avg(), 2));
            x.setCpc16_avg(MathUtil.tofixed(x.getCpc16_avg(), 2));
            x.setEpc1_avg(MathUtil.tofixed(x.getEpc1_avg(), 2));
            x.setEpc2_avg(MathUtil.tofixed(x.getEpc2_avg(), 2));
            x.setCpcpor1_strip_pos_avg(MathUtil.tofixed(x.getCpcpor1_strip_pos_avg(), 2));
            x.setCpcpor2_strip_pos_avg(MathUtil.tofixed(x.getCpcpor2_strip_pos_avg(), 2));
            x.setCpc1_strip_pos_avg(MathUtil.tofixed(x.getCpc1_strip_pos_avg(), 2));
            x.setCpc2_strip_pos_avg(MathUtil.tofixed(x.getCpc2_strip_pos_avg(), 2));
            x.setCpc3_strip_pos_avg(MathUtil.tofixed(x.getCpc3_strip_pos_avg(), 2));
            x.setCpc4a_strip_pos_avg(MathUtil.tofixed(x.getCpc4a_strip_pos_avg(), 2));
            x.setCpc4_strip_pos_avg(MathUtil.tofixed(x.getCpc4_strip_pos_avg(), 2));
            x.setCpc5a_strip_pos_avg(MathUtil.tofixed(x.getCpc5a_strip_pos_avg(), 2));
            x.setCpc5_strip_pos_avg(MathUtil.tofixed(x.getCpc5_strip_pos_avg(), 2));
            x.setCpc6_strip_pos_avg(MathUtil.tofixed(x.getCpc6_strip_pos_avg(), 2));
            x.setCpc7_strip_pos_avg(MathUtil.tofixed(x.getCpc7_strip_pos_avg(), 2));
            x.setCpc8_strip_pos_avg(MathUtil.tofixed(x.getCpc8_strip_pos_avg(), 2));
            x.setCpc9_strip_pos_avg(MathUtil.tofixed(x.getCpc9_strip_pos_avg(), 2));
            x.setCpc10_strip_pos_avg(MathUtil.tofixed(x.getCpc10_strip_pos_avg(), 2));
            x.setCpc11_strip_pos_avg(MathUtil.tofixed(x.getCpc11_strip_pos_avg(), 2));
            x.setCpc12_strip_pos_avg(MathUtil.tofixed(x.getCpc12_strip_pos_avg(), 2));
            x.setCpc13_strip_pos_avg(MathUtil.tofixed(x.getCpc13_strip_pos_avg(), 2));
            x.setCpc14_strip_pos_avg(MathUtil.tofixed(x.getCpc14_strip_pos_avg(), 2));
            x.setCpc15_strip_pos_avg(MathUtil.tofixed(x.getCpc15_strip_pos_avg(), 2));
            x.setCpc16a_strip_pos_avg(MathUtil.tofixed(x.getCpc16a_strip_pos_avg(), 2));
            x.setCpc16_strip_pos_avg(MathUtil.tofixed(x.getCpc16_strip_pos_avg(), 2));
            x.setEpc1_strip_pos_avg(MathUtil.tofixed(x.getEpc1_strip_pos_avg(), 2));
            x.setEpc2_strip_pos_avg(MathUtil.tofixed(x.getEpc2_strip_pos_avg(), 2));
        });
        return list;
    }
}
